package com.attack.manager;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import com.attack.model.CustomerInfoModel;
import com.common.manager.BaseManager;
import com.framework.model.IData;
import com.framework.model.impl.DataMap;

/**
 * 客户资料管理服务类
 * @author Administrator
 *
 */
@Service(value = "customerInfoManager")
public class CustomerInfoManager extends BaseManager {

	@Override
	public void setSqlMapNameSpace() {
	    
		this.sqlMapNameSpace = "com.attack.manager.model.CustomerInfo";

	}
	
	
	/**
	 * 功能：加载机构员工树
	 * @param roleId
	 * @return
	 */
	public String loadOrgStaffTreeList(String roleIds){
		IData idata = new DataMap();
		String menuUrl = "management/customer/pageList.do";
		idata.put("roleIds", roleIds);
		JSONArray treeList = new JSONArray();
		List  orgStaffList = super.getObjectList("getOrgStaffTreeList",idata);
		if(orgStaffList!=null){
			JSONObject orgObj = new JSONObject();
			for (int i = 0; i < orgStaffList.size(); i++) {
				//jsonString.append("{id:1, pId:0, name:\"父节点1 - 展开\", open:true},");
				IData objData =  (DataMap) orgStaffList.get(i);
				orgObj = new JSONObject();
				orgObj.put("id", objData.get("id"));
				orgObj.put("name",objData.get("label"));
				orgObj.put("pId",objData.get("pId"));
				if("C".equals(objData.get("typeFlag"))){
					orgObj.put("url",menuUrl+"?staffNum="+ objData.get("id")+"&orgCode="+ objData.get("orgCode"));
					orgObj.put("icon", "static/ztree/treep.png");
				}else{
					orgObj.put("open", true);
					orgObj.put("url",menuUrl+"?orgCode="+ objData.get("orgCode"));
					orgObj.put("icon", "static/ztree/8.png");
				}
				treeList.add(orgObj);
			}
		}
	  log.info(treeList.toString());
	  return treeList.toString();
	}

	
	/**
	 * 功能：订单机构人员树
	 * @param roleId
	 * @return
	 */
	public String loadOrderTree(String roleIds){
		IData idata = new DataMap();
		String menuUrl = "management/order/pageList.do";
		idata.put("roleIds", roleIds);
		JSONArray treeList = new JSONArray();
		List  orgStaffList = super.getObjectList("getOrgStaffTreeList",idata);
		if(orgStaffList!=null){
			JSONObject orgObj = new JSONObject();
			for (int i = 0; i < orgStaffList.size(); i++) {
				//jsonString.append("{id:1, pId:0, name:\"父节点1 - 展开\", open:true},");
				IData objData =  (DataMap) orgStaffList.get(i);
				orgObj = new JSONObject();
				orgObj.put("id", objData.get("id"));
				orgObj.put("name",objData.get("label"));
				orgObj.put("pId",objData.get("pId"));
				if("C".equals(objData.get("typeFlag"))){
					orgObj.put("url",menuUrl+"?staffNum="+ objData.get("id")+"&orgCode="+ objData.get("orgCode"));
					orgObj.put("icon", "static/ztree/treep.png");
				}else{
					orgObj.put("open", true);
					orgObj.put("url",menuUrl+"?orgCode="+ objData.get("orgCode"));
					orgObj.put("icon", "static/ztree/8.png");
				}
				treeList.add(orgObj);
			}
		}
	  log.info(treeList.toString());
	  return treeList.toString();
	}
	
	
	/**
	 * 功能：提供给订单表使用选择员工对应的客户列表
	 * @param staffNum
	 * @return
	 */
	public String getCustListByStaffNum(String staffNum){
		IData idata = new DataMap();
		String menuUrl = "management/order/pageList.do";
		idata.put("staffNum", staffNum);
		JSONArray custArr = new JSONArray();
		List<CustomerInfoModel>  customerList = super.getObjectList(idata);
		if(customerList!=null){
			JSONObject objJson;
			for (CustomerInfoModel customerInfoModel : customerList) {
				objJson = new JSONObject();
				objJson.put("value", customerInfoModel.getIntID());
				objJson.put("label", customerInfoModel.getCustName());
				custArr.add(objJson);
			}
		}
		return custArr.toString();
	}
	
	
}
